package com.qubuyer.business.auth.viewmodel

import androidx.lifecycle.MutableLiveData
import com.qubuyer.business.auth.model.AuthModel
import com.qubuyer.core.anno.AutoInject
import com.qubuyer.core.framework.BaseViewModel
import com.qubuyer.core.http.RetrofitCall

/**
 * Author: linwg
 * Time: 2021/3/11 0011
 * Description:
 */
class ForgetPwdViewModel : BaseViewModel() {
    @AutoInject
    private val authModel = AuthModel()
    val getCodeResult = MutableLiveData<Boolean>()
    val result = MutableLiveData<Int>()

    fun getCode(phone: String) {
        RetrofitCall<String?>(lifecycleOwner, this) {
            api { authModel.verifySms(phone) }
            success {
                getCodeResult.value = true
            }
            fail { _, _, _ ->
                getCodeResult.value = false
            }
        }
    }

    fun findPwd(phone: String,  code: String,pwd: String, pwd2: String) {
        RetrofitCall<String?>(lifecycleOwner, this) {
            api { authModel.forgetPassword(phone, pwd, code, pwd2) }
            success {
                result.value = 200
            }
        }
    }
}